<!-- 
* @desc:分槽管理槽队列单个元素
* @fileName:SlotItem.vue
* @author:chenxiaofeng@yzbdl.ac.cn
* @date:2022-05-31
!-->
<script lang="ts" setup>
import { reactive } from "vue";

const slotData = reactive({
  slotItem: [
    {
      id: 1,
      status: 1,
      slotName: "槽队列-1",
      noFinish: 95,
      finish: 3567,
      collectorName: "数据采集执行器-1",
      memory: 33,
      taskSuccess: 100,
    },
    {
      id: 2,
      status: 2,
      slotName: "槽队列-2",
      noFinish: 125,
      finish: 4167,
      collectorName: "数据采集执行器-1",
      memory: 75,
      taskSuccess: 90,
    },
  ],
  activeItem: 1,
});
</script>

<template>
  <div
    class="slot-item"
    :class="{ actived: slotData.activeItem === item.id }"
    v-for="(item, index) in slotData.slotItem"
    :index="item.id + '+' + index"
  >
    <div class="right-arrow"></div>
    <div class="slot-item-line-1">
      <div class="slot-item-line-1-icon">
        <template v-if="item.status === 1">
          <img src="@/assets/img/slot-manage/normal.png" />
        </template>
        <template v-else>
          <img src="@/assets/img/slot-manage/abnormal.png" />
        </template>
      </div>
      <span class="slot-item-line-1-title">{{ item.slotName }}</span>
      <dl>
        <dt>{{ item.noFinish }}</dt>
        <dd>未结束实例</dd>
      </dl>
      <dl>
        <dt>{{ item.finish }}</dt>
        <dd>已结束实例</dd>
      </dl>
    </div>
    <div class="slot-item-line-2">
      <div class="slot-item-line-2-icon">
        <img src="@/assets/img/slot-manage/icon.png" />
      </div>
      <span class="slot-item-line-2-title">{{ item.collectorName }}</span>
      <el-popover
        placement="top-start"
        :width="250"
        trigger="hover"
        content="this is content, this is content, this is content"
      >
        <template #reference>
          <div class="slot-item-line-2-info">
            <img src="@/assets/img/slot-manage/index-noraml.png" />
            <span>查看指标</span>
          </div>
        </template>
        <template #default>
          <div class="flex">
            <div class="slot-item-hover-info">
              <div
                v-if="item.memory < 50"
                class="dialog-info"
                :style="{
                  background:
                    'linear-gradient(to top, #96f5b3 ' +
                    item.memory +
                    '%, #fff 0)',
                }"
              >
                <template v-if="item.memory < 50"
                  ><img src="@/assets/img/slot-manage/cpu-noraml.png"
                /></template>
                <template v-else
                  ><img src="@/assets/img/slot-manage/cpu-warning.png"
                /></template>
              </div>
              <div
                v-else
                class="dialog-info"
                :style="{
                  background:
                    'linear-gradient(to top, #ffb7b7 ' +
                    item.memory +
                    '%, #fff 0)',
                }"
              >
                <template v-if="item.memory < 50"
                  ><img src="@/assets/img/slot-manage/cpu-noraml.png"
                /></template>
                <template v-else
                  ><img src="@/assets/img/slot-manage/cpu-warning.png"
                /></template>
              </div>
              <dl>
                <dt>{{ item.memory }}%</dt>
                <dd>内存占用率</dd>
              </dl>
            </div>
            <div class="slot-item-hover-info">
              <div
                class="dialog-info"
                :style="{
                  background:
                    'linear-gradient(to top, #9bafff ' +
                    item.taskSuccess * 0.8 +
                    '%, #fff 0)',
                }"
              >
                <img src="@/assets/img/slot-manage/task-success.png" />
              </div>
              <dl>
                <dt class="slot-item-success-rate">{{ item.taskSuccess }}%</dt>
                <dd>任务成功率</dd>
              </dl>
            </div>
          </div>
        </template>
      </el-popover>
      <div class="slot-item-line-2-info server">
        <img src="@/assets/img/slot-manage/server.png" />
        <span>所在服务器</span>
      </div>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.actived {
  box-shadow: 0px 0px 30px rgba($color: #000000, $alpha: 0.16);
  .right-arrow {
    display: block;
  }
}
.right-arrow {
  width: 16px;
  height: 16px;
  background-color: #fff;
  transform: rotate(45deg) scale(1.22);
  position: absolute;
  right: -5px;
  top: 43px;
  display: none;
}
$blueColor: #2a83de;
.slot-item {
  position: relative;
  background-color: #fff;
  margin-bottom: 20px;
  transition: all 0.3s;
  cursor: pointer;
  &:hover {
    box-shadow: 0px 0px 30px rgba($color: #000000, $alpha: 0.16);
  }
}
.slot-item-line-1 {
  padding: 0 18px 0 10px;
  display: flex;
  height: 56px;
  align-items: center;
  dl {
    margin: 0;
    width: 120px;
    dd,
    dt {
      text-align: right;
    }
    dt {
      font-size: 14px;
      font-weight: 700;
      color: #000;
    }
    dd {
      font-size: 12px;
      color: #000;
    }
  }
  .slot-item-line-1-title {
    flex: 1;
    font-size: 20px;
    color: #000;
    font-weight: 700;
  }
  .slot-item-line-1-icon {
    margin-right: 10px;
    img {
      width: 16px;
      height: 16px;
      position: relative;
      top: 2px;
    }
  }
}
.slot-item-line-2 {
  padding: 0 18px 0 10px;
  display: flex;
  align-items: center;
  height: 43px;
  border-top: 1px solid rgba($color: #707070, $alpha: 0.2);
  .slot-item-line-2-icon {
    margin-right: 10px;
    img {
      width: 14px;
      height: 14px;
    }
  }
  .slot-item-line-2-title {
    flex: 1;
    font-size: 14px;
    color: $blueColor;
    font-weight: 700;
    text-decoration: underline;
    text-underline-offset: 5px;
    cursor: pointer;
    position: relative;
    top: -3px;
  }

  .slot-item-line-2-info {
    width: 120px;
    text-align: right;
    img {
      width: 16px;
      height: 16px;
      margin-right: 10px;
      position: relative;
      top: 3px;
    }
    span {
      color: #000;
      font-size: 14px;
      cursor: pointer;
      &:hover {
        color: $blueColor;
        font-weight: 700;
      }
    }
  }
  .server {
    img {
      width: 13px;
      height: 16px;
    }
  }
}
.slot-item-hover-info {
  flex: 1;
  display: flex;
  margin: 0;
  &:nth-of-type(2) {
    margin-left: 18px;
  }
  img {
    width: 40px;
    height: 36px;
    flex-shrink: 0;
    margin-right: 10px;
  }
  .slot-item-success-rate {
    color: #2d55f8;
  }
  dl {
    width: 60px;
    flex-shrink: 0;
    margin: 0;
    dt {
      font-size: 14px;
      font-weight: 700;
      text-align: right;
    }
    dd {
      text-align: right;
      margin: 0;
      font-size: 12px;
      color: #000;
    }
  }
}
.flex {
  display: flex;
  width: 100%;
}
.dialog-info {
  width: 40px;
  height: 36px;
  margin-right: 10px;
}
</style>
